package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/10.
 */
@HttpInlet(Conn.INLET_GET_EXP_DETAIL)
public class GetExpenseDetail extends JTAsyGet<GetExpenseDetail.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public String userId = JTApplication.jtPreferences.readUserID();

    public String date = "";

    public GetExpenseDetail(AsyCallBack<Info> asyCallBack) {
        super(asyCallBack);
    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        JSONObject body = apiTYF.optJSONObject("body");

        JSONArray expenseList = body.optJSONArray("mpList");

        if (expenseList != null) {

            for (int i = 0; i < expenseList.length(); i++) {

                JSONObject object_exp = expenseList.optJSONObject(i);

                ExpenseDetailList mItem = new ExpenseDetailList();

                mItem.name = object_exp.optString("name");

                mItem.price = object_exp.optString("price");

                mItem.time = object_exp.optString("time");

                info.expenseDetailLists.add(mItem);

            }

        }

        return info;


    }

    public static class Info implements Serializable {

        public String msg;

        public List<ExpenseDetailList> expenseDetailLists = new ArrayList<>();

    }

    public static class ExpenseDetailList implements Serializable {

        public String time, price, name;


    }


}
